package com.alexgaoyh.MutiModule.Dubbo.RWSeperate.consumer.web.sysman.sysmanRole;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.MutiModule.common.twitter.IDGenerator.instance.IdWorkerInstance;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanRole.read.ISysmanRoleReadService;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanRole.write.ISysmanRoleWriteService;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.sysman.sysmanRole.SysmanRole;
import com.alexgaoyh.MutiModule.Dubbo.RWSeperate.persist.sysman.sysmanRole.SysmanRoleExample;
import com.alibaba.dubbo.config.annotation.Reference;

/**
*
* dubbo 消费者
 * SysmanRole 模块 读接口
 * @author alexgaoyh
*
*/
@Controller
@RequestMapping(value="manager/sysmanRole")
public class SysmanRoleController {

	@Reference(group="readService", interfaceName="com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanRole.read.ISysmanRoleReadService")
	private ISysmanRoleReadService sysmanRoleReadService;
	
	@Reference(group="writeService", interfaceName="com.alexgaoyh.MutiModule.Dubbo.RWSeperate.api.sysman.sysmanRole.write.ISysmanRoleWriteService")
	private ISysmanRoleWriteService sysmanRoleWriteService;
	
	@RequestMapping(value = "/index")
	public ModelAndView index(ModelAndView model, HttpServletRequest request) {
		SysmanRoleExample example = new SysmanRoleExample();
		example.setOrderByClause("id desc");
		List<SysmanRole> list = sysmanRoleReadService.selectByExample(example);
		model.addObject("list", list);
		model.setViewName("manager/sysman/sysmanRole/index");
		return model;
	}
	
	@RequestMapping(value = "/save")
	public ModelAndView save(ModelAndView model, HttpServletRequest request) {
		SysmanRole record = new SysmanRole();
		record.setId(IdWorkerInstance.getId());
		record.setName(new Date().toString());
		record.setCreateTime(new Date());
		record.setDescription(new Date().toString());
		
		sysmanRoleWriteService.insert(record);
		
		model.setViewName("redirect:index");
		return model;
	}

}
